<template>
    <div class="app-container">
        <el-row :gutter="20">
            <!--部门数据-->
            <el-col :span="4" :xs="24">
                <fileTrees @handleNodeClick="onTreeClick" :tableHeight="treeHeight" :isnoClick="isnoClick" :menuId="menuId">
                </fileTrees>

            </el-col>
            <!--离线接收数据-->
            <el-col :span="20" :xs="24" v-show="isShow">

                <queryCriteriaList v-if="listFrom.length > 0" :showSearch="showSearch" :listFrom="listFrom"
                    @resetQuery="resetQuery" @handleQuery="handleQuery" ref="queryForm"></queryCriteriaList>
                    <!-- {{(subStr == 'F' && categoryType == 0) || (subStr == 'V' && categoryType == 1) || (subStr == 'X' && categoryType == 3)}} -->
                <el-row :gutter="10" class="mb8" ref="refbut">
                    <el-col :span="1.5"
                        v-show="(subStr == 'F' && categoryType == 0) || (subStr == 'V' && categoryType == 1) || (subStr == 'X' && categoryType == 3)">
                        <el-button type="primary" plain icon="el-icon-takeaway-box" @click="handleJieshouTap()"
                            v-hasPermi="['archive:lxjs:jieshou']">接收</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="primary" plain icon="el-icon-plus" v-show="(subStr == 'X' && categoryType == 3)"
                            @click="handledeitTap(0)" v-hasPermi="['archive:lxjs:addItem']">项目著录</el-button>
                        <!--案卷著录-->
                        <el-button type="primary" plain icon="el-icon-plus" v-show="(subStr == 'V')"
                            @click="handledeitTap(0)" v-hasPermi="['archive:lxjs:addFolder']">著录</el-button>
                        <!--件著录-->
                        <el-button type="primary" plain icon="el-icon-plus" v-show="(subStr == 'F')"
                            @click="handledeitTap(0)" v-hasPermi="['archive:lxjs:addYqda']">著录</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <!--项目修改-->
                        <el-button type="success" plain icon="el-icon-edit" v-show="(subStr == 'X')"
                            @click="handledeitTap(1)" v-hasPermi="['archive:lxjs:updateItem']">修改</el-button>
                        <!--案卷修改-->
                        <el-button type="success" plain icon="el-icon-edit" v-show="(subStr == 'V')"
                            @click="handledeitTap(1)" v-hasPermi="['archive:lxjs:updateFolder']">修改</el-button>
                        <!--件修改-->
                        <el-button type="success" plain icon="el-icon-edit" v-show="(subStr == 'F')"
                            @click="handledeitTap(1)" v-hasPermi="['archive:lxjs:updateYqda']">修改</el-button>

                    </el-col>
                    <el-col :span="1.5">
                        <!--项目删除-->
                        <el-button type="danger" plain icon="el-icon-delete" v-show="(subStr == 'X')"
                            @click="handleDeleteTap('1')" v-hasPermi="['archive:wjzl:delete1']">删除</el-button>
                        <!--案卷删除-->
                        <el-button type="danger" plain icon="el-icon-delete" v-show="(subStr == 'V')"
                            @click="handleDeleteTap('2')" v-hasPermi="['archive:wjzl:delete2']">删除</el-button>
                        <!--件删除-->
                        <el-button type="danger" plain icon="el-icon-delete" v-show="(subStr == 'F')"
                            @click="handleDeleteTap('3')" v-hasPermi="['archive:wjzl:delete3']">删除</el-button>

                    </el-col>
                    <el-col :span="1.5">
                        <!--  @click="handleImport" -->
                        <!--件导入-->
                        <el-button type="primary" plain icon="el-icon-upload2" v-show="subStr == 'F'" @click="handleImport"
                            v-hasPermi="['archive:wjzl:daoru1']">导入</el-button>
                        <!--项目导入-->
                        <el-button type="primary" plain icon="el-icon-upload2" v-show="subStr == 'X'" @click="handleImport"
                            v-hasPermi="['archive:wjzl:daoru2']">导入</el-button>
                        <!--项目层的案卷导入-->
                        <el-button type="primary" plain icon="el-icon-upload2" v-show="subStr == 'X'"
                            @click="handleImportFolder" v-hasPermi="['archive:wjzl:anjuandaoru1']">案卷导入</el-button>
                        <!--案卷层的案卷导入-->
                        <el-button type="primary" plain icon="el-icon-upload2" v-show="subStr == 'V'"
                            @click="handleImportFolder" v-hasPermi="['archive:wjzl:anjuandaoru2']">案卷导入</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <!-- //调用打印打开可看效果 -->
                        <!-- <el-button type="warning" plain icon="el-icon-printer"
                            @click="printTap">目录打印</el-button> -->

                        <el-button type="warning" plain icon="el-icon-printer" @click="print1Tap"
                            v-hasPermi="['archive:wjzl:muludayin']">目录打印</el-button>

                    </el-col>

                    <el-col :span="1.5" v-show="subStr == 'V'">
                        <el-button type="primary" plain icon="el-icon-printer" @click="handleImportFile()"
                            v-hasPermi="['archive:wjzl:juanneijiandaoru']">卷内件导入</el-button>
                    </el-col>

                    <el-col :span="1.5" v-show="subStr == 'X'">
                        <el-button type="primary" plain icon="el-icon-printer" @click="handledeitanJuanTap()"
                            v-hasPermi="['archive:lxjs:addFolder1']">案卷著录</el-button>
                    </el-col>

                    <el-col :span="1.5" v-show="subStr == 'X'">
                        <el-button type="primary" plain icon="el-icon-printer" @click="handledeitanDeitJuanTap()"
                            v-hasPermi="['archive:lxjs:updateFolder1']">案卷修改</el-button>
                    </el-col>
                    <el-col :span="1.5" v-show="subStr == 'X'">
                        <el-button type="primary" plain icon="el-icon-document-delete" @click="handleCaiXMTap()"
                            v-hasPermi="['archive:lxjs:splitItem']">拆项目</el-button>
                    </el-col>
                    <el-col :span="1.5" v-show="subStr == 'V' && (categoryType == 3)">
                        <el-button type="primary" plain icon="el-icon-remove-outline" @click="handleJuanORXMTap()"
                            v-hasPermi="['archive:lxjs:delItemFolderByFolderId']">清除卷和项目关系</el-button>
                    </el-col>

                    <el-col :span="1.5" v-show="subStr == 'F' && (categoryType == 1 || categoryType == 3)">
                        <!--组件类型档案不展示组卷按钮-->
                        <el-button type="primary" plain icon="el-icon-files" @click="mergeYqdaTap(1)"
                            v-hasPermi="['archive:lxjs:mergeYqda']">组卷</el-button>

                    </el-col>
                    <el-col :span="1.5" v-show="subStr == 'V' && categoryType == 3">
                        <el-button type="primary" plain icon="el-icon-files" @click="mergeFolder"
                            v-hasPermi="['archive:lxjs:mergeFolder']">组项目</el-button>
                    </el-col>

                    <el-col :span="1.5"
                        v-show="(subStr == 'V' && categoryType == 1) || (subStr == 'V' && categoryType == 3)">
                        <el-button type="primary" plain icon="el-icon-files" @click="mergeYqdaTap(2)"
                            v-hasPermi="['archive:lxjs:assemblyFolder']">合并卷</el-button>
                    </el-col>
                    <el-col :span="1.5"
                        v-show="(subStr == 'V' && categoryType == 1) || (subStr == 'V' && categoryType == 3)">
                        <el-button type="primary" plain icon="el-icon-files" @click="splitFolderTap"
                            v-hasPermi="['archive:lxjs:splitFolder']">拆卷</el-button>
                    </el-col>

                    <el-col :span="1.5" v-show="subStr == 'F' && (categoryType == 1 || categoryType == 3)">
                        <el-button type="success" plain icon="el-icon-plus" @click="submitTap"
                            v-hasPermi="['archive:lxjs:tijiao']">提交</el-button>
                    </el-col>

                    <el-col :span="1.5" v-show="(subStr == 'F' && categoryType == '3') || (subStr == 'F' && categoryType == '1') || (subStr == 'F' && categoryType == '0')">
                      <el-button type="primary" plain icon="el-icon-printer" @click="printHandover()"
                                 v-hasPermi="['archive:lxjs:printHandover']" >打印移交清单</el-button>
                    </el-col>
                    <right-toolbar :showSearch.sync="showSearch" @queryTable="queryTableTap"></right-toolbar>
                </el-row>
                <tableList v-if="tableHeight" :tableHeaderList="tableHeaderList"
                    @handleSelectionChange="handleSelectionChange" :tableData="tableData" :loading="loading"
                    :tableHeight="tableHeight" @celldblclick="celldblclick" @sortChange="sortChange" ref="ref"></tableList>
                <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize" @pagination="getlistPost" />
            </el-col>

            <el-col :span="20" :xs="24" v-show="!isShow" class="empty">
                <el-empty :image-size="200"></el-empty>
            </el-col>

        </el-row>
        <!-- start 组件著录、修改 -->
        <jiandeit v-if="jianOpen" :open="jianOpen" :openInfo="openInfo" @closeDelDialog="closeDelDialog"
            @submitDetail="submitDetail" @submitTooDetail="submitTooDetail" :isParams="1">
        </jiandeit>
        <!-- end  组件著录、修改-->

        <!-- start 组卷著录、修改 -->
        <juandeit v-if="juanOpen" :open="juanOpen" :openInfo="openInfo" @closeDelDialog="closeDelDialog"
            @submitDetail="submitDetail" :isParams="1" :isZUXIU="isZUXIU" :isShow="isShowButton"></juandeit>
        <!-- end  组卷著录、修改-->

        <!-- start 项目著录  修改 -->
        <projectdeit v-if="projectOpen" :open="projectOpen" :openInfo="openInfo" @submitDetail="submitDetail"
            @closeDelDialog="closeDelDialog" :isParams="1"></projectdeit>
        <!-- end 项目著录、修改 -->
        <!--start  组件详情 -->
        <jianDetailsOpen v-if="jianDetailsOpen" :open="jianDetailsOpen" :celldbData="celldbData"
            @detailsHandleClose="detailsHandleClose">
        </jianDetailsOpen>
        <!--end 组件详情 -->
        <!-- start 组卷\项目详情 -->
        <juanDetailsOpen v-if="juanDetailsOpen" :open="juanDetailsOpen" :celldbData="celldbData" module="fileCollection" :isParams="1"
             :treeRowData="treeRowData" @detailsHandleClose="detailsHandleClose"></juanDetailsOpen>
        <!-- end 组卷\项目详情 -->

        <!-- start  目录打印 -->
        <vPrint v-if="printOpen" :open="printOpen" @closeDelDialog="closeDelDialog" :tableHeaderList="tableHeaderList"
            :printList="printList"></vPrint>
        <!-- end  目录打印 -->
        <!-- start 项目下面的卷列表修改 -->
        <projectJuanlistDeit v-if="projectJuanlistDeitOpen" :open="projectJuanlistDeitOpen" :celldbData="celldbData"
            @detailsHandleClose="detailsHandleClose" :openInfo="openInfo" :isParams="1" :isShow="isShowButton">
        </projectJuanlistDeit>
        <!-- end  项目下面的卷列表修改 -->

        <!-- 用户导入对话框 -->
        <dataImport :upload="upload" @uploadCancel="uploadCancelTap" @importTemplate="importTemplateTap"
            @uploadFile="uploadFile" @submitFileForm="submit"></dataImport>

        <!-- 导入匹配页 -->
        <importMatch :match="match" ref="matchRef" @matchCancel="matchCancelTap" @submitMatch="submitMatch"></importMatch>
    </div>
</template>
<script>
import {
    splitItem,
    assemblyFolderVerify,
    delItemFolderByFolderId,
    getqueryfieldList,
    getlistbytreenodeList,
    getthbytreenodeHeaderList,
    deleteData,
    jieshou,
    splitFolder,
    geturl,
    getTitle,
    uploadList,
    submitButton, deleteData1, deleteData2, deleteData3, downloadDocx
} from "@/api/archive/fileCollection/offlinReception.js";
import queryCriteriaList from "@/components/queryCriteriaList/index.vue"  //查询列表
import fileTrees from "@/components/fileTrees/index.vue"  //档案树
import { getGroupTree } from "@/api/archive/archivesCategory.js"
import tableList from "@/components/tableList/index2.vue"
import jiandeit from "@/views/archive/fileCollection/offlinReception/jiandeit.vue" //件添加修改弹窗
import juandeit from "@/views/archive/fileCollection/offlinReception/juandeit.vue" //卷添加修改弹窗
import projectdeit from "@/views/archive/fileCollection/offlinReception/projectdeit.vue" //卷添加修改弹窗
import projectJuanlistDeit from "@/views/archive/fileCollection/offlinReception/projectJuanlistDeit.vue" //项目下面的卷列表修改
import treeHeight from '@/mixins/treeHeight'//计算左侧树的高度
import jianDetailsOpen from '@/components/componentsJianDetails/index.vue' //件详情
import juanDetailsOpen from '@/components/componentsJuanDetails/index.vue' //卷详情
import vPrint from "@/components/printComponent/index.vue" //目录打印弹窗模板
import dataImport from "@/components/dataImportComponent/dataImport.vue";
import importMatch from "@/components/dataImportComponent/importMatch.vue";
import { getLastIndexOf } from "@/utils/index.js"
import { getTypeObject } from '@/api/archive/dict/dictManageData'
import { getDicts_archive } from "@/api/homePage";
import {getRouters} from "@/api/menu";
import {getInfo} from "@/api/login";

export default {
    mixins: [treeHeight], // 混入方法
    components: {
        queryCriteriaList,
        fileTrees,
        jiandeit,
        juandeit,
        tableList,
        projectdeit,
        jianDetailsOpen,
        juanDetailsOpen,
        vPrint,
        dataImport,
        importMatch,
        projectJuanlistDeit
    },
    data() {
        return {
            isnoClick: true, //防止树重复点击
            isButtonType: "",//按钮是否展示
            scroll: "",
            loading: false,
            // 显示搜索条件
            showSearch: true,
            listFrom: [], //查询框列表
            isShow: false, //是否显示右侧数据 isShow:true,  //判断  著录项目内件按钮是否显示
            isShowButton: true,
            total: 0,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 20,
            },
            tableHeaderList: [], //table表头数据
            tableData: [],//table列表数据
            jianOpen: false, //组件打开关闭
            juanOpen: false, //组卷打开关闭
            projectOpen: false,//项目打开关闭
            jianDetailsOpen: false,//件详情弹窗
            juanDetailsOpen: false,//卷详情弹窗
            projectJuanlistDeitOpen: false,//项目下面的卷列表修改
            openInfo: { //件 卷  项目
                opens: false,
                categoryId: undefined,
                menuId: undefined,
                type: undefined
            },
            tableHeight: "",
            ids: undefined,
            single: "",
            multiple: "",
            rowList: "",//当前点击的数据
            treeRowData: "", //点击档案树显示当前点击数据
            subStr: "",  //获取点击当前树的 件 卷  项目 截取 sub_table_name显示
            categoryType: "",
            printOpen: false, //打印弹出传
            printList: [],
            responselist: "",//门类详情
            infoSrorage: "",

            // 用户导入参数
            upload: {
                // 是否显示弹出层（用户导入）
                open: false,
                // 弹出层标题（用户导入）
                title: "",
            },
            // 导入文件类型  件、卷、项目
            uploadType: null,
            // 表格表头
            xlsTitle: [],
            // 可导入项
            sysTitle: [],
            // 匹配参数
            match: {
                // 是否显示弹出层
                open: false,
                // 弹出层标题
                title: "",
            },
            isTypeMLID: "",
            menuId: '',
            isZUXIU: "",
            dictList: [],
            // 路由地址
            routeList: []
        }
    },

    created() {
        this.menuId = this.$route.meta.menuId
        // getRouters().then(res => {
        //   this.routeList = res.data
        // })
    },


    methods: {

        //动态设置table的高度
        tableHeightData() {
            this.$nextTick(
                () => {
                    let h = document.documentElement.clientHeight
                    //     console.log(this.$refs.queryForm.$el.offsetHeight, this.$refs.refbut.$el.offsetHeight, "sdklfjklliuhaiorng")
                    h = h - 200
                    if (this.$refs.queryForm) { // 页面上如果有面包屑区域徐减去它的高度
                        h = h - this.$refs.queryForm.$el.offsetHeight
                    }

                    if (this.$refs.refbut) { // 页面上如果有分页区域徐减去它的高度
                        h = h - this.$refs.refbut.$el.offsetHeight
                    }
                    // console.log(h,"sdjfdklsjfkl")
                    this.tableHeight = h > 310 ? h : 310 // 根据自己项目定高度

                    return h
                }
            )

        },

        // 树节点单击事件
        onTreeClick(data) {
            console.log(data)
            this.isnoClick = false;
            this.treeRowData = data;

            if (data.categoryId != null) {
                this.isShow = true
            } else {
                this.isShow = false
            }
            if (this.$refs.queryForm != undefined) {
                this.$refs.queryForm.queryParams = {};
            }
            if (data.nodeType == null || data.nodeType == "t" || data.nodeType == "f") {
                this.isnoClick = true;
                return false;

            }
            this.loading = true;
            this.queryParams = data;
            this.queryParams.order = '';
            this.queryParams.state = 1;
            this.queryParams.jsType = 0;
            this.queryParams.pageNum = 1;
            this.queryParams.pageSize = 20;
            if (this.queryParams.sub_table_name != undefined) {
                this.subStr = getLastIndexOf(this.queryParams.sub_table_name);
                let stb = this.queryParams.sub_table_name;
                let stbArr = stb.split("_");

                this.categoryType = stbArr[stbArr.length - 3];
            } else {
                this.getGroupTreePost(data.categoryId);
            }
            this.getqueryfieldListPost();//点击树节点获取查询字段
            this.getlistHeaderPost();/**点击树节点,获取table表头数据 */
            if(this.$refs.ref!=undefined){
                this.$refs.ref.clearSort()
            }

        },


        //档案门类树门类根据categoryID回显
        getGroupTreePost(ID) {
            getGroupTree(ID).then(response => {
                if (response.data.type == "0") { //件
                    this.queryParams.sub_table_name = response.data.fileTableName;
                } else if (response.data.type == "1") { //卷
                    this.queryParams.sub_table_name = response.data.folderTableName;
                } else { //项目
                    this.queryParams.sub_table_name = response.data.itemTableName;
                }
                this.subStr = getLastIndexOf(this.queryParams.sub_table_name);
                let stb = this.queryParams.sub_table_name;

                let stbArr = stb.split("_");
                this.categoryType = stbArr[stbArr.length - 3];
            });
        },


        /** 点击树节点获取查询字段 */
        getqueryfieldListPost(data) {
            this.queryParams.searchcolumn = undefined
            console.log(this.queryParams)
            getqueryfieldList({
                categoryId: this.queryParams.categoryId,
                menuId: this.queryParams.menuId,
                subTableName: this.queryParams.sub_table_name,
            }).then(response => {
                this.listFrom = response.rows;

            });
        },

        /**点击树节点,获取table表头数据 */
        getlistHeaderPost() {
            getthbytreenodeHeaderList({
                categoryId: this.queryParams.categoryId, menuId: this.queryParams.menuId, subTableName: this.queryParams.sub_table_name
            }
            ).then(response => {
                this.tableHeaderList = response.rows;
                var fields = []
                for (var i in response.rows) {
                    fields.push(response.rows[i].FIELD_NAME)
                }
                this.queryParams.fields = fields.toString()
                //获取指定字典列表
                var headerlist = [];
                for (var i = 0; i < this.tableHeaderList.length; i++) {
                    if (this.tableHeaderList[i].SHOWTYPE.toString().indexOf('5') != -1) {
                        this.tableHeaderList[i].SHOWTYPE = 5
                    }
                    if (this.tableHeaderList[i].SHOWTYPE == 5) {
                        // console.log(this.tableHeaderList[i])
                        headerlist.push(this.tableHeaderList[i].FIELD_NAME)
                    }
                }

                if (headerlist.length > 0) {
                    getTypeObject(headerlist).then((res) => {
                        this.dictList = res.data;
                    })
                }
                this.getlistPost();
                this.isnoClick = true;
            });
        },
        /** 点击树节点,获取table数据*/
        getlistPost() {
            var that = this;
            this.loading = true;
            if (this.queryParams.fields==''){
              this.$message({ message: '请先对该门类进行配置！', type: 'warning' })
              return ;
            }
            getlistbytreenodeList(this.queryParams).then(response => {
                this.tableData = response.rows;
                this.total = response.total;
                this.loading = false;
                this.tableHeightData();
                // this.isnoClick = true;
            });
        },
        //是否选择数据
        handleSelectionChange(ids, oagdbs,single, multiple) {
            this.ids = ids.toString();
            this.single = single;
            this.multiple = multiple;
        },

        //表单重置
        resetQuery() {
            this.queryParams.searchcolumn = undefined
            this.queryParams.order = undefined;
            this.getlistPost();
            this.$refs.ref.clearSort()   //情况排序样式
        },
        //点击搜索
        handleQuery(searchcolumn) {
            var column = searchcolumn.filter(item => { return item.value !== '' && item.value !== null })
            this.queryParams.searchcolumn = column
            this.queryParams.order = undefined;
            this.getlistPost();
            this.$refs.ref.clearSort()
        },
        //刷新页面
        queryTableTap(){
            this.queryParams.order = undefined;
            this.getlistPost();
            this.$refs.ref.clearSort()
        },
        //件  this.jianOpen  著录和修改     //组卷 this.juanOpen 著录和修改    //项目 this.projectdOpen 著录和修改
        handledeitTap(e) {
            // console.log
            this.openInfo = {
                opens: true,
                categoryId: this.queryParams.categoryId,
                menuId: this.queryParams.menuId,
                folderId: undefined, //组卷id
                itemId: undefined, //项目Id
                subTableName: this.queryParams.sub_table_name,
                nodeType: this.queryParams.nodeType,
                parentNodeType: this.queryParams.parentNodeType,
                parentSubTableName: this.queryParams.parentSubTableName,
                subStr: this.subStr,
            }
            // console.log(this.openInfo)
            if (e == 1) {  //修改
                if (this.ids == undefined) {
                    this.$message({ message: '请选择要修改的数据哦', type: 'warning' })
                    return false
                }
                if (this.single) {
                    this.$message({ message: '请选择一条要修改的数据哦', type: 'warning' })
                    return false
                }

                this.openInfo.ids = this.ids; //组件Id;
            } else { //添加
                this.openInfo.ids = undefined
            }
            if (this.subStr == "F") {  //F 件
                this.openInfo.type = 0
                this.jianOpen = true
            } else if (this.subStr == "V") { //卷
                this.openInfo.type = 1
                this.juanOpen = true;
            } else { //项目
                this.openInfo.type = 3
                this.projectOpen = true;
            }

        },

        //给组卷 卷内件导入
        handledeitanJianTap() {
            this.openInfo = {
                opens: true,
                categoryId: this.queryParams.categoryId,
                menuId: this.queryParams.menuId,
                folderId: undefined, //组卷id
                itemId: undefined, //项目Id
                subTableName: this.queryParams.sub_table_name,
                nodeType: this.queryParams.nodeType,
                parentNodeType: this.queryParams.parentNodeType,
                parentSubTableName: this.queryParams.parentSubTableName,
                subStr: this.subStr,
                type: 0, //传卷类型  0,组件 1，组卷 3，项目
            }
            if (this.ids == undefined) {
                this.$message({ message: '请选择先选择数据哦', type: 'warning' })
                return false
            }
            if (this.single) {
                this.$message({ message: '请选择一条数据哦', type: 'warning' })
                return false
            }
            this.openInfo.itemId = this.ids; //项目Id;
            this.jianOpen = true;
        },
        //给项目案卷著录
        handledeitanJuanTap() {
            this.isZUXIU = "1" //判断项目下的案卷是著录还是修改
            if (this.ids == undefined) {
                this.$message({ message: '请选择先选择数据哦', type: 'warning' })
                return false
            }
            if (this.single) {
                this.$message({ message: '请选择一条数据哦', type: 'warning' })
                return false
            }
            var row = this.tableData.filter(item => { return this.ids == item.ID })
            this.openInfo = {
                opens: true,
                categoryId: this.queryParams.categoryId,
                menuId: this.queryParams.menuId,
                type: 1, //传卷类型  0,组件 1，组卷 3，项目
                folderId: undefined, //组卷id
                itemId: this.ids, //项目Id
                subTableName: this.queryParams.sub_table_name,
                subStr: this.subStr,
                label: row[0].XMMC
            }
            this.openInfo.button = 'xmajzl' // 项目案卷修改
            this.openInfo.itemId = this.ids; //项目Id;
            this.juanOpen = true;
        },


        // //给项目案件著录
        // handledeitanJuanTap() {
        //     this.openInfo = {
        //         opens: true,
        //         categoryId: this.queryParams.categoryId,
        //         menuId: this.queryParams.menuId,
        //         type: 1, //传卷类型  0,组件 1，组卷 3，项目
        //         folderId: undefined, //组卷id
        //         itemId: undefined, //项目Id
        //         subTableName: this.queryParams.sub_table_name
        //     }
        //     if (this.ids == undefined) {
        //         this.$message({ message: '请选择先选择数据哦', type: 'warning' })
        //         return false
        //     }
        //     if (this.single) {
        //         this.$message({ message: '请选择一条数据哦', type: 'warning' })
        //         return false
        //     }
        //     this.openInfo.itemId = this.ids; //项目Id;
        //     this.juanOpen = true;
        // },

        //关闭著录 \件\ 组卷\目录打印
        closeDelDialog() {
            this.jianOpen = false //件
            this.juanOpen = false //卷
            this.projectOpen = false; //项目
            this.printOpen = false;//目录打印
            this.openInfo = "";
            this.getlistHeaderPost();
        },

        //著录成功
        submitDetail() {
            this.jianOpen = false;
            this.juanOpen = false //卷
            this.projectOpen = false; //项目
            this.getlistHeaderPost();
        },

        //继承追加成功
        submitTooDetail() {
            this.getlistHeaderPost();
        },

        //删除
        handleDeleteTap(val) {
            if (this.ids != undefined && !this.multiple) {
                this.$modal.confirm('是否确认删除所选数据项？').then(function () {
                }).then(() => {
                    let type = "";
                    if (this.subStr == "F") {  //F 件
                        type = 0;
                    } else if (this.subStr == "V") { //卷
                        type = 1;
                    } else { //项目
                        type = 3;
                    }
                    if (val == '1') {
                        deleteData1({
                            type: type,
                            //nodeType: this.queryParams.nodeType,
                            categoryId: this.queryParams.categoryId,
                            //sub_table_name: this.queryParams.sub_table_name,
                            //menuId: this.queryParams.menuId,
                            //parentNodeType: this.queryParams.parentNodeType,
                            //parentSubTableName: this.queryParams.parentSubTableName,
                            ids: this.ids
                        }).then((res) => {
                            if (res.code == "200") {
                                this.getlistPost();
                                this.$modal.msgSuccess("删除成功");
                            }
                        })
                    } else if (val == '2') {
                        deleteData2({
                            type: type,
                            //nodeType: this.queryParams.nodeType,
                            categoryId: this.queryParams.categoryId,
                            //sub_table_name: this.queryParams.sub_table_name,
                            //menuId: this.queryParams.menuId,
                            //parentNodeType: this.queryParams.parentNodeType,
                            //parentSubTableName: this.queryParams.parentSubTableName,
                            ids: this.ids
                        }).then((res) => {
                            if (res.code == "200") {
                                this.getlistPost();
                                this.$modal.msgSuccess("删除成功");
                            }
                        })
                    } else if (val == '3') {
                        deleteData3({
                            type: type,
                            //nodeType: this.queryParams.nodeType,
                            categoryId: this.queryParams.categoryId,
                            //sub_table_name: this.queryParams.sub_table_name,
                            //menuId: this.queryParams.menuId,
                            //parentNodeType: this.queryParams.parentNodeType,
                            //parentSubTableName: this.queryParams.parentSubTableName,
                            ids: this.ids
                        }).then((res) => {
                            if (res.code == "200") {
                                this.getlistPost();
                                this.$modal.msgSuccess("删除成功");
                            }
                        })
                    }

                }).catch(() => { });
            } else {
                this.$message({ message: '请选择要删除的数据哦', type: 'warning' })
            }
        },

        //组卷 合并卷
        mergeYqdaTap(val) {
            if (this.ids != undefined && !this.multiple) {
                if (val == 1) {
                    var IDS = this.ids.split(",")
                    var datas = [];
                    for (var i in this.tableData) {
                        for (var j in IDS) {
                            if (this.tableData[i].ID == IDS[j]) {
                                if (this.tableData[i].IS_ZUJUAN == 1) {
                                    datas.push(this.tableData[i].TITLE)
                                }
                            }
                        }
                    }
                    if (datas.length > 0) {
                        this.$message({ message: '选择的数据已经组卷', type: 'warning' })
                        return
                    }
                    this.openInfo = {
                        opens: true,
                        categoryId: this.queryParams.categoryId,
                        menuId: this.queryParams.menuId,
                        folderId: undefined, //组卷id
                        itemId: undefined, //项目Id
                        subTableName: this.queryParams.sub_table_name,
                        nodeType: this.queryParams.nodeType,
                        parentNodeType: this.queryParams.parentNodeType,
                        parentSubTableName: this.queryParams.parentSubTableName,
                        subStr: this.subStr,
                        type: 1,
                        ids: this.ids,
                        isDisabled: val //判断如果从组卷按钮和合并卷按钮进去带参isDisabled，只可以将件组成卷或者将多个卷里面的件合并，不可以在里面添加件
                    }

                    this.juanOpen = true;
                } else {
                    assemblyFolderVerify({
                        categoryId: this.queryParams.categoryId,
                        folderIds: this.ids
                    }).then(res => {
                        this.openInfo = {
                            opens: true,
                            categoryId: this.queryParams.categoryId,
                            menuId: this.queryParams.menuId,
                            folderId: undefined, //组卷id
                            itemId: undefined, //项目Id
                            subTableName: this.queryParams.sub_table_name,
                            nodeType: this.queryParams.nodeType,
                            parentNodeType: this.queryParams.parentNodeType,
                            parentSubTableName: this.queryParams.parentSubTableName,
                            subStr: this.subStr,
                            type: 1,
                            ids: this.ids,
                            isDisabled: val //判断如果从组卷按钮和合并卷按钮进去带参isDisabled，只可以将件组成卷或者将多个卷里面的件合并，不可以在里面添加件
                        }

                        this.juanOpen = true;
                    }).catch(res => {
                        // this.$message({ message:res.msg, type: 'warning' })
                    })
                }



            } else {
                this.$message({ message: '请选择要操作的数据哦', type: 'warning' })
            }
        },

        //拆卷
        splitFolderTap() {
            if (this.ids != undefined && !this.multiple) {
                splitFolder({
                    categoryId: this.queryParams.categoryId,
                    folderIds: this.ids
                }).then(res => {
                    // console.log(res)
                    if (res.code == "200") {
                        this.$modal.msgSuccess("拆卷成功");
                        this.getlistHeaderPost();
                    }
                })
            } else {
                this.$message({ message: '请选择要操作的数据哦', type: 'warning' })
            }
        },

        //组项目
        mergeFolder() {
            if (this.ids != undefined && !this.multiple) {
                var IDS = this.ids.split(",")
                var datas = [];
                for (var i in this.tableData) {
                    for (var j in IDS) {
                        if (this.tableData[i].ID == IDS[j]) {
                            if (this.tableData[i].IS_PROJECT == 1) {
                                datas.push(this.tableData[i].TITLE)
                            }

                        }
                    }
                }
                if (datas.length > 0) {
                    this.$message({ message: '请选择未组项目的数据哦！', type: 'warning' })
                    return
                }
                this.openInfo = {
                    opens: true,
                    categoryId: this.queryParams.categoryId,
                    menuId: this.queryParams.menuId,
                    folderId: undefined, //组卷id
                    itemId: undefined, //项目Id
                    subTableName: this.queryParams.sub_table_name,
                    nodeType: this.queryParams.nodeType,
                    parentNodeType: this.queryParams.parentNodeType,
                    parentSubTableName: this.queryParams.parentSubTableName,
                    subStr: this.subStr,
                    type: 3,
                    ids: this.ids,
                    isDisabled: 3   //组项目
                }
                this.projectOpen = true;
            } else {
                this.$message({ message: '请选择要操作的数据哦', type: 'warning' })
            }
        },
        //接收
        handleJieshouTap() {

            if (this.ids != undefined && !this.multiple) {
                this.$modal.confirm('是否确认接收所选数据数据项？').then(function () {
                }).then(() => {
                    jieshou({
                        categoryId: this.queryParams.categoryId,
                        ids: this.ids
                    }).then(res => {
                        this.getlistPost();
                        this.$modal.msgSuccess("接收成功");
                        // 跳转文件整理 有就跳转无就不跳转
                        // if(this.hasRoute("fileOrganizationMenu")){
                        //   setTimeout(res => {
                        //     this.$router.push({ path: "/fileCollection/fileOrganizationMenu" })
                        //   }, 1000)
                        // }
                        setTimeout(res => {
                            getDicts_archive('JUMP_ADDRESS').then(response => {
                                console.log(response,"路由")
                                var url = response.data.filter(res => { return res.dictValue == "WJZL" })


                                if(url.length>0){
                                    this.$router.push({ path: url[0].dictLabel })
                                }

                            })

                        }, 1000)
                    })

                }).catch(() => { });
            } else {
                this.$message({ message: '请选择要接收的数据哦', type: 'warning' })
            }
        },
        hasRoute(path, routeList) {
          !routeList && (routeList = this.routeList, console.log('执行'))
          console.log(routeList)
          for (let i = 0; i < routeList.length; i++) {
            console.log(routeList[i].path)
            if (routeList[i].path == path) {
              return true
            }
            if (routeList[i].children) {
              let flag = this.hasRoute(path, routeList[i].children)
              if(flag){
                return flag
              }
            }
          }
          return false
        },



        //双击列表进入详情页面
        celldblclick(row) {
            var level = "";
            var label = "";
            if (getLastIndexOf(this.queryParams.sub_table_name) == "F") {  //F 件
                level = 0
                label = row.TITLE;
            } else if (getLastIndexOf(this.queryParams.sub_table_name) == "V") { //卷
                level = 1
                label = row.TITLE;
            } else { //项目
                level = 3
                label = row.XMMC;
            }

            this.celldbData = {
                id: row.ID,
                categoryId: this.queryParams.categoryId,
                menuId: this.queryParams.menuId,
                sub_table_name: this.queryParams.sub_table_name,
                label: label,
                level: level,
                ifSub_table_name: this.queryParams.sub_table_name,
                isDel: "0",  //判断是回收站数据还是接收收据 isDel:1  回收站    isDel:0 //离线接收、档案接收、在线接收
                tableHeaderList: this.tableHeaderList
            }
            this.$nextTick(() => {
                if (this.subStr == "F") {  //F 进入件详情
                    this.jianDetailsOpen = true;
                } else { //进入卷详情 和项目详情
                    this.juanDetailsOpen = true
                }
            })

        },

        //修改项目下面的案卷
        handledeitanDeitJuanTap() {
            var that = this;
            this.isZUXIU = "2" //判断项目下的案卷是著录还是修改
            if (this.ids == undefined) {
                this.$message({ message: '请选择先选择数据哦', type: 'warning' })
                return false
            }
            if (this.single) {
                this.$message({ message: '请选择一条数据哦', type: 'warning' })
                return false
            }
            var row = this.tableData.filter(item => { return this.ids == item.ID })
            var level = "";
            if (getLastIndexOf(this.queryParams.sub_table_name) == "F") {  //F 件
                level = 0
            } else if (getLastIndexOf(this.queryParams.sub_table_name) == "V") { //卷
                level = 1
            } else { //项目
                level = 3
            }
            this.openInfo = {
                opens: true,
                categoryId: this.queryParams.categoryId,
                menuId: this.queryParams.menuId,
                folderId: undefined, //组卷id
                itemId: this.ids, //项目Id
                subTableName: this.responselist.fileTableName,
                nodeType: "l",
                subStr: "V",
                type: 1
            }
            this.openInfo.button = 'xmajxg' // 项目案卷著录
            this.celldbData = {
                id: row[0].ID,
                categoryId: this.queryParams.categoryId,
                menuId: this.queryParams.menuId,
                sub_table_name: this.queryParams.sub_table_name,
                label: row[0].XMMC,
                level: level,
                ifSub_table_name: this.queryParams.sub_table_name,
                isDel: "0",  //判断是回收站数据还是接收收据 isDel:1  回收站    isDel:0 //离线接收、档案接收、在线接收
            }
            that.projectJuanlistDeitOpen = true
        },

        //关闭详情页面
        detailsHandleClose() {
            this.jianDetailsOpen = false;
            this.juanDetailsOpen = false;
            this.projectJuanlistDeitOpen = false;
        },

        //排序
        sortChange(val) {
            this.queryParams.order = val;

            this.getlistPost();

        },

        //打印目录
        printTap() {
            this.printList = [];
            if (this.ids != undefined && !this.multiple) {
                this.printOpen = true
                var idsData = this.ids.split(",")
                for (var i in this.tableData) {
                    for (var j in idsData) {
                        if (this.tableData[i].ID == idsData[j]) {
                            this.printList.push(this.tableData[i])
                        }
                    }
                }
            } else {
                this.$message({ message: '请选择要打印的数据哦', type: 'warning' })
            }
        },

        print1Tap() {
            var data = [];
            this.printList = [];
            if (this.ids != undefined && !this.multiple) {

                getlistbytreenodeList(this.queryParams).then(response => {
                    var printTableData = response.rows;
                    this.getPrintList(printTableData, this.queryParams.sub_table_name)

                });

            } else {
                this.$message({ message: '请选择要打印的数据哦', type: 'warning' })
            }
        },


        //处理好的打印数据方法
        getPrintList(printTableData, sub_table_name) {
            var that = this;
            var data = [];
            var datalist = ['data']
            this.printList = [];
            var idsData = this.ids.split(",")
            for (var i in this.tableHeaderList) {
                if (this.tableHeaderList[i].SHOWTYPE == 5) {
                    for (var j in printTableData) {
                        // console.log(printTableData[j])
                        for (var x in this.dictList[this.tableHeaderList[i].FIELD_NAME]) {
                            if (printTableData[j][this.tableHeaderList[i].FIELD_NAME] == this.dictList[this.tableHeaderList[i].FIELD_NAME][x].dictValue) {
                                printTableData[j][this.tableHeaderList[i].FIELD_NAME] = this.dictList[this.tableHeaderList[i].FIELD_NAME][x].dictLabel
                            }
                        }
                    }
                }
            }

            var printList = [];
            for (var c in printTableData) {
                for (var k in idsData) {
                    if (printTableData[c].ID == idsData[k]) {
                        printList.push(printTableData[c])
                    }
                }
            }
            data = [{ data: printList }];
            geturl({
                categoryId: this.queryParams.categoryId,
                menuId: this.queryParams.menuId,
                type: getLastIndexOf(sub_table_name),
                data: JSON.stringify(data),
                datalist: JSON.stringify(datalist)
            }).then(res => {
                if (res.data.result == "fail") {
                    this.$message({ message: res.data.msg, type: 'warning' })
                } else {
                    window.open(res.data.url);
                }


            })
        },

        // 导入按钮  组件/项目
        handleImport() {
            if (this.subStr == "F") {
                // console.log("件导入")
                this.upload.title = "卷内件数据";
                this.upload.open = true;
                this.uploadType = 0
            } else {
                // console.log("项目导入")
                this.upload.title = "项目数据";
                this.upload.open = true;
                this.uploadType = 3
            }
        },
        // 案卷导入
        handleImportFolder() {
            if (this.subStr == 'X') {
                if (this.ids == undefined) {
                    this.$message({ message: '请选择先选择数据哦', type: 'warning' })
                    return false
                }
                if (this.single) {
                    this.$message({ message: '请选择一条数据哦', type: 'warning' })
                    return false
                }
            }
            // console.log("案卷导入")
            this.upload.title = "案卷数据";
            this.upload.open = true;
            this.uploadType = 1
        },
        //给组卷 卷内件导入
        handleImportFile() {
            if (this.ids == undefined) {
                this.$message({ message: '请选择先选择数据哦', type: 'warning' })
                return false
            }
            if (this.single) {
                this.$message({ message: '请选择一条数据哦', type: 'warning' })
                return false
            }
            // console.log("件导入")
            this.upload.title = "卷内件数据";
            this.upload.open = true;
            this.uploadType = 0
        },
        // 关闭导入  /件/卷/项目
        uploadCancelTap() {
            this.upload.open = false;
            this.getlistHeaderPost();
        },
        // 下载模板
        importTemplateTap() {
            this.form = {
                type: this.uploadType,
                categoryId: this.queryParams.categoryId
            }
            if (this.uploadType == 0) {
                // console.log("卷内件下载模板")
                this.download('/archive/daImport/download?type=' + this.uploadType + "&categoryId=" + this.queryParams.categoryId, {
                }, `fileData_template_${new Date().getTime()}.xlsx`)
            } else if (this.uploadType == 1) {
                // console.log("案卷下载模板")
                this.download('/archive/daImport/download?type=' + this.uploadType + "&categoryId=" + this.queryParams.categoryId, {
                }, `folderData_template_${new Date().getTime()}.xlsx`)
            } else {
                // console.log("项目下载模板")
                this.download('/archive/daImport/download?type=' + this.uploadType + "&categoryId=" + this.queryParams.categoryId, {
                }, `itemData_template_${new Date().getTime()}.xlsx`)
            }
        },
        // 上传文件
        uploadFile(concent) {
            this.file = concent.file
            const formData = new FormData();
            formData.append("file", concent.file);
            formData.append("categoryId", this.queryParams.categoryId);
            formData.append("type", this.uploadType);
            getTitle(formData).then(response => {
                this.xlsTitle = response.data.xlsTitle.map(item => {
                    return {
                        xlsNum: item.num,
                        xlsName: item.name
                    }
                })
                this.sysTitle = response.data.sysTitle.map(item => {
                    return {
                        name: item.fieldName,
                        caption: item.fieldCaption,
                        showType: item.showType,
                        dataLength: item.dataLength,
                        isNoEmpty: item.isNoEmpty,
                        defaultValue: item.defaultValue,
                        checkChongfu: item.checkChongfu
                    }
                })
                this.$nextTick(() => {   //此函数执行时所有的DOM挂载和渲染都已完成
                    console.log( this.$refs.matchRef,"------------------------")
                    this.$refs.matchRef.init(this.xlsTitle, this.sysTitle);     //获取子组件中init方法并将父组件数据传递给子组件
                });
            })
        },

        // 点击确认
        submit() {
            // console.log("打开匹配页")
            this.upload.open = false
            this.match.open = true
            if (this.uploadType == 0) {
                this.match.title = "卷内件导入"
            } else if (this.uploadType == 1) {
                this.match.title = "案卷导入"
            } else {
                this.match.title = "项目导入"
            }
            // this.$nextTick(() => {   //此函数执行时所有的DOM挂载和渲染都已完成
            //     this.$refs.matchRef.init(this.xlsTitle, this.sysTitle);     //获取子组件中init方法并将父组件数据传递给子组件
            // });
        },
        submitMatch(matchedData) {
            this.form = {
                categoryId: this.queryParams.categoryId,
                state: this.queryParams.state,
                jsType: this.queryParams.jsType,
                colNames: matchedData
            }
            if (this.subStr == "F") {
                this.form.type = this.uploadType
                // if (this.uploadType == 0) {
                //     this.form.type = this.uploadType
                //     this.form.folderId = "-1"
                // } else {
                //     this.form.type = this.uploadType
                // }
            } else if (this.subStr == "V") {
                if (this.uploadType == 0) {
                    this.form.type = 0
                    this.form.folderId = this.ids
                } else {
                    this.form.type = this.uploadType
                }
            } else {
                if (this.uploadType == 1) {
                    this.form.type = 1
                    this.form.itemId = this.ids
                } else {
                    this.form.type = this.uploadType
                }
            }
            const formData = new FormData();
            formData.append("file", this.file);
            formData.append("dataStr", JSON.stringify(this.form));
            uploadList(formData).then(response => {
                this.$modal.msgSuccess(response.msg);
                // this.match.open = false;
                this.getlistPost()
            })
            this.match.open = false;
        },
        matchCancelTap() {
            this.match.open = false;
        },

        //移除卷和项目关系
        handleJuanORXMTap() {
            if (this.ids != undefined && !this.multiple) {
                this.$modal.confirm('是否确认清除卷和项目关系的数据项？').then(function () {
                }).then(() => {
                    delItemFolderByFolderId({
                        categoryId: this.queryParams.categoryId,
                        folderIds: this.ids
                    }).then(res => {
                        this.getlistPost();
                        this.$modal.msgSuccess("操作成功");
                    })

                }).catch(() => { });
            } else {
                this.$message({ message: '请选择要清除卷和项目关系的数据哦', type: 'warning' })
            }

        },

        //拆项目
        handleCaiXMTap() {

            if (this.ids != undefined && !this.multiple) {
                this.$modal.confirm('是否确认拆项目？').then(function () {
                }).then(() => {
                    splitItem({
                        categoryId: this.queryParams.categoryId,
                        itemIds: this.ids
                    }).then(res => {
                        this.getlistPost();
                        this.$modal.msgSuccess("操作成功");
                    })

                }).catch(() => { });
            } else {
                this.$message({ message: '请选择要拆项目的数据哦', type: 'warning' })
            }
        },

        // 提交
        submitTap() {
            if (this.ids != undefined && !this.multiple) {
                this.$modal.confirm('是否确认提交给兼职档案管理员？').then(function () {
                }).then(() => {
                    submitButton({
                        categoryId: this.queryParams.categoryId,
                        ids: this.ids
                    }).then(res => {
                        this.getlistPost();
                        this.$modal.msgSuccess("操作成功");
                    }).catch(() => { });
                }).catch(() => { });
            } else {
                this.$modal.msgWarning('请选择数据进行提交')
            }
        },

      // 打印移交清单
      printHandover() {
        if (this.ids != undefined && !this.multiple) {
          const ids = this.ids.split(',')
          downloadDocx({categoryId: this.queryParams.categoryId, archiveIds: ids }).then((res) => {
            // 创建一个 Blob 对象，用于存储二进制数据
            if (res.data.result == "fail") {
              this.$message({ message: res.data.msg, type: 'warning' })
            } else {
              window.open(res.data.url);
            }
          });
        } else {
          this.$message({ message: '请选择数据哦', type: 'warning' })
        }
      }
    }
}
</script>

